#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
struct book
{
	char name[31];
	double price;
};
int main()
{
	int n, i;
	struct book books[10];
	scanf("%d", &n);
	if (n == 0) return 0;
	for (i = 0; i < n; i++) {
		scanf("\n");
		gets_s(books[i].name);
		scanf("%lf", &books[i].price);
	}
	int max = 0, min = 0;
	for (i = 1; i < n; i++) {
		if (books[i].price > books[max].price) {
			max = i;
		}
		if (books[i].price < books[min].price) {
			min = i;
		}
	}
	printf("%.2f, %s\n", books[max].price, books[max].name);
	printf("%.2f, %s\n", books[min].price, books[min].name);

	return 0;
}